package com.ruoyi.controller.jpjs.project;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.service.SysParameterService;
import com.ruoyi.service.jpjs.param.ParamService;
import com.ruoyi.service.jpjs.person.PersonService;
import com.ruoyi.service.jpjs.project.ProjectServiceGG;
import com.ruoyi.system.service.ISysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/projectManageGG")
public class ProjectManageControllerGG extends BaseController {

    private String prefix = "jpjs/projectgg";

    @Autowired
    private ProjectServiceGG projectService;
    @Autowired
    private ParamService paramService;
    @Autowired
    private PersonService personService;
    @Autowired
    private SysParameterService sysParameterService;

    @Autowired
    private ISysDictDataService sysDictDataService;

    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String projectManage(ModelMap mmp) {
        mmp.put("proType", paramService.findParam("项目类型"));
        mmp.put("proStatus", paramService.findParam("项目状态"));
        mmp.put("belongComp", paramService.findParam("区域公司"));
        return prefix + "/ProjectManage";
    }

    @GetMapping("/map")
    public String map(String proPosition, ModelMap mmp) {
        mmp.put("proPosition", proPosition);
        return prefix + "/Map1";
    }

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo findProject(@RequestParam Map<String, Object> map) {
        startPage();
        List<Map<String, Object>> list = projectService.findProjectList(map);
        return getDataTable(list);
    }

    @GetMapping("/add")
    public String addProject(ModelMap mmp) {
        mmp.put("proType", paramService.findParam("项目类型"));
        mmp.put("proStatus", paramService.findParam("项目状态"));
        mmp.put("belongComp", paramService.findParam("区域公司"));
        mmp.put("proPerson", personService.findPersonName("项目负责人"));
        mmp.put("businessPerson", personService.findPersonName("商务负责人"));
        mmp.put("technicalPerson", personService.findPersonName("技术负责人"));
        mmp.put("infoPerson", personService.findPersonName("信息化负责人"));
        mmp.put("building", sysDictDataService.selectDictDataByType("build_number"));
        return prefix + "/AddProjectManage";
    }

    @PostMapping("/save")
    @ResponseBody
    public AjaxResult savePorject(@RequestParam Map<String, Object> map) {
        return toAjax(projectService.savePorject(map));
    }

    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult removeProject(String ids) {
        return toAjax(projectService.removePorject(ids));
    }

    @GetMapping("/edit/{id}")
    public String editProject(@PathVariable("id") String id, ModelMap mmp) {
        mmp.put("proType", paramService.findParam("项目类型"));
        mmp.put("proStatus", paramService.findParam("项目状态"));
        mmp.put("belongComp", paramService.findParam("区域公司"));
        mmp.put("proPerson", personService.findPersonName("项目负责人"));
        mmp.put("businessPerson", personService.findPersonName("商务负责人"));
        mmp.put("technicalPerson", personService.findPersonName("技术负责人"));
        mmp.put("infoPerson", personService.findPersonName("信息化负责人"));
        mmp.put("project", projectService.findProject(id));
        mmp.put("building", projectService.getBuildingByName(id));
        mmp.put("buildingAll", sysDictDataService.selectDictDataByType("build_number"));
        return prefix + "/editProjectManage";
    }

    @PostMapping("/view")
    @ResponseBody
    public List<Map<String, Object>> getView() {
        return projectService.getProView();
    }

    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(@RequestParam Map<String, Object> map) {
        return projectService.export(map);
    }

    @PostMapping("/identifier")
    @ResponseBody
    public String identifier() {
        return projectService.identifier();
    }
}
